package com.ld.hpfs.web.controller;

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.ld.hpfs.common.jackson.JackJson;
import com.ld.hpfs.pojo.ExtPager;
import com.ld.hpfs.pojo.User;
import com.ld.hpfs.service.DealSendMsgService;
import com.ld.hpfs.web.interseptor.WebConstants;
import com.ld.hpfs.common.utils.Const;
import com.ld.hpfs.common.utils.GmailSender;
import com.ld.hpfs.common.utils.GmailSenderInfo;
import com.ld.hpfs.common.utils.SimpleMailSender;
import com.ld.hpfs.common.utils.MailSenderInfo;
import com.ld.hpfs.common.utils.Tools;

@Controller
public class DealSendMsgController {
	private static final Logger logger = LoggerFactory
			.getLogger(DealSendMsgController.class);

	@Autowired
	private DealSendMsgService dealsendmsgservice;
	
	/**
	 * 得到寄送通知一览信息
	 */
	@RequestMapping(value = "/getDealSendList")
	public void getDealSendList(ExtPager page, HttpSession session,
			HttpServletRequest request, HttpServletResponse response,
			PrintWriter writer) {

		HashMap<String, Object> param = new HashMap<String, Object>();
		HashMap<String, Object> result = new HashMap<String, Object>();
		response.setContentType("text/plain;charset=UTF-8");
		String doc_no = request.getParameter("doc_no");
		String cust_code = request.getParameter("cust_code");
		
		//单据号的开始和结束范围
		String DOCUMENT_NO_First = (String)request.getParameter("startno") == "" ? null : (String)request.getParameter("startno");		
		String DOCUMENT_NO_End = (String)request.getParameter("endno") == "" ? null : (String)request.getParameter("endno");		
		//得到一个或多个单据号	
		String DOCUMENT_NO = (String)request.getParameter("nos") == "" ? null : (String)request.getParameter("nos");				
	    //快递单号
		String sexpressno = (String)request.getParameter("sexpressno") == "" ? null : (String)request.getParameter("sexpressno");
		String eexpressno = (String)request.getParameter("eexpressno") == "" ? null : (String)request.getParameter("eexpressno");
		//日期
		String  DateFirst = (String)request.getParameter("startday") == "" ? null : (String)request.getParameter("startday");
		String  DateEnd = (String)request.getParameter("endday") == "" ? null : (String)request.getParameter("endday");				
		//客户名称
		String custname = (String)request.getParameter("custom") == "" ? null : (String)request.getParameter("custom");		
		//系统语言环境
		String language = (String) session.getAttribute(WebConstants.CURRENT_LANG);
		try {
			User user = (User) session.getAttribute(WebConstants.CURRENT_USER);
			if (user != null) {
				param.put("DOCUMENT_NO_First", DOCUMENT_NO_First);
				param.put("DOCUMENT_NO_End", DOCUMENT_NO_End);
				param.put("DateFirst", DateFirst==null?null:DateFirst.substring(0, 10));
				param.put("DateEnd", DateEnd==null?null:DateEnd.substring(0, 10));
		        param.put("custname", custname);
		        param.put("sexpressno", sexpressno);
		        param.put("eexpressno",eexpressno);
		        param.put("companyId", session.getAttribute(WebConstants.CURRENT_COMPANY));
		        param.put("language", language);
		        //对单据号进行判断不为空的话放入集合之中
				if(DOCUMENT_NO!=null && DOCUMENT_NO !=""){
					List<HashMap<String,String>> lists = new ArrayList<HashMap<String,String>>();
					String[] nos = DOCUMENT_NO.split(",");
					HashMap<String,String> map= new HashMap<String,String>();
					for(int i=0;i<nos.length;i++){
						map = new HashMap<String,String>();
						map.put("nos", nos[i]);
						lists.add(map);
					}
					param.put("DOCUMENT_NO", lists);
				}else{
					param.put("DOCUMENT_NO", null);
				}
				
				param.put("doc_no", doc_no);
				param.put("cust_code", cust_code);
				param.put("pageEnd", page.getStart() + page.getLimit());
				param.put("pageStart", page.getStart());
				ArrayList<HashMap<String, Object>> logs = dealsendmsgservice
						.getDealSendList(param);
				if (logs != null && logs.size() > 0) {
					result.put("success", true);
					result.put("total", param.get("pageCount"));
					result.put("data", logs);
				} else {
					result.put("success", true);
					result.put("total", param.get("pageCount"));
					result.put("data", "");
				}
				String returnMsg = JackJson.fromObjectToJson(result);
				logger.debug("{}", returnMsg);
				writer.print(returnMsg);
			} else {
				writer.print("");
			}
		} catch (Exception e) {
			logger.error("Exception: ", e);
		} finally {
			writer.flush();
			writer.close();
		}
	}

	/**
	 * 邮件短信预览
	 */
	@RequestMapping(value = "/mailPreview")
	public void mailPreview(ExtPager page, HttpSession session,
			HttpServletRequest request, HttpServletResponse response,
			PrintWriter writer) {

		HashMap<String, Object> param = new HashMap<String, Object>();
		HashMap<String, Object> result = new HashMap<String, Object>();
		response.setContentType("text/plain;charset=UTF-8");
		// 单据号码
		String doc_no = request.getParameter("doc_no");
		String cpnId = session.getAttribute(WebConstants.CURRENT_COMPANY).toString();
		try {
			User user = (User) session.getAttribute(WebConstants.CURRENT_USER);
			if (user != null) {
 				param.put("doc_no", doc_no);
 				param.put("cpnId", cpnId);
 				param.put("type", 1);
 				// 获得邮件短信设置信息
 				ArrayList<HashMap<String, Object>> logsformodel = dealsendmsgservice.getMsgForPreview(param);
 				int useFlag = Integer.parseInt(logsformodel.get(0).get("useFlag").toString());
 				if (useFlag == 2 || useFlag == 3) {
 				// 获得邮件信息
 	 				ArrayList<HashMap<String, Object>> logsfordata = dealsendmsgservice.getMsgForReplace(param);
 	 				
 	 				String review_to = "";
 	 				String review_cc = "";
 	 				String review_bcc = "";
 	 				String review_subject = "";
 	 				String review_email = "";
 	 				String review_msg = "";
 	 				String recipient_name = "";
 	 				String recipient_email = "";
 	 				String cpn_name = "";
 	 				String express_cpn = "";
 	 				String express_no = "";
 	 				String express_data = "";
 	 				boolean flag = false;
 	 				try {
 	 					// 收件人
 	 					if (!Tools.isEmpty(logsformodel.get(0).get("review_to"))) {
 	 						review_to = logsformodel.get(0).get("review_to").toString();
 	 					}
 	 					if (!Tools.isEmpty(logsformodel.get(0).get("review_cc"))) {
 	 						review_cc = logsformodel.get(0).get("review_cc").toString();
 	 					}
 	 					if (!Tools.isEmpty(logsformodel.get(0).get("review_bcc"))) {
 	 						review_bcc = logsformodel.get(0).get("review_bcc").toString();
 	 					}
 	 					if (!Tools.isEmpty(logsformodel.get(0).get("review_subject"))) {
 	 						review_subject = logsformodel.get(0).get("review_subject").toString();
 	 					}
 	 					if (!Tools.isEmpty(logsformodel.get(0).get("review_email"))) {
 	 						// 邮件内容
 	 	 	 				review_email = logsformodel.get(0).get("review_email").toString();
 	 					}
 	 					if (!Tools.isEmpty(logsformodel.get(0).get("review_msg"))) {
 	 						// 短信内容
 	 	 	 				review_msg = logsformodel.get(0).get("review_msg").toString();
 	 					}
						if (!Tools.isEmpty(logsfordata.get(0).get("recipient_name"))) {
							// 收件人名称
	 	 	 				recipient_name = logsfordata.get(0).get("recipient_name").toString();
						}
						if (!Tools.isEmpty(logsfordata.get(0).get("recipient_email"))) {
							// 收件人邮箱
	 	 	 				recipient_email = logsfordata.get(0).get("recipient_email").toString();
						}
						if (!Tools.isEmpty(logsfordata.get(0).get("cpn_name"))) {
							// 公司名称
	 	 	 				cpn_name = logsfordata.get(0).get("cpn_name").toString();
						}
						if (!Tools.isEmpty(logsfordata.get(0).get("express_cpn"))) {
							// 快递公司
	 	 	 				express_cpn = logsfordata.get(0).get("express_cpn").toString();
						}
						if (!Tools.isEmpty(logsfordata.get(0).get("express_no"))) {
							// 快递单号
	 	 	 				express_no = logsfordata.get(0).get("express_no").toString();
						}
						if (!Tools.isEmpty(logsfordata.get(0).get("express_data"))) {
							// 日期
	 	 	 				express_data = logsfordata.get(0).get("express_data").toString();
						}
 	 	 				
 	 	 				// to
 	 					if(review_to.contains("[收件人邮箱]")){
 	 						review_to = review_to.replace("[收件人邮箱]", recipient_email);
 	 					}
 	 					// cc
 	 					if(review_cc.contains("[收件人邮箱]")){
 	 						review_cc = review_cc.replace("[收件人邮箱]", recipient_email);
 	 					}
 	 					// bcc
 	 					if(review_bcc.contains("[收件人邮箱]")){
 	 						review_bcc = review_bcc.replace("[收件人邮箱]", recipient_email);
 	 					}
 	 					// subject
 	 					if(review_subject.contains("[公司名称]")){
 	 						review_subject = review_subject.replace("[公司名称]", cpn_name);
 	 					}
 	 					if(review_subject.contains("[快递单号]")){
 	 						review_subject = review_subject.replace("[快递单号]", express_no);
 	 					}
 	 					if(review_subject.contains("[日期]")){
 	 						review_subject = review_subject.replace("[日期]", express_data);
 	 					}
 	 					// mail
 	 					if(review_email.contains("[收件人名称]")){
 	 						review_email = review_email.replace("[收件人名称]", recipient_name);
 	 					}
 	 					if(review_email.contains("[公司名称]")){
 	 						review_email = review_email.replace("[公司名称]", cpn_name);
 	 					}
 	 					if(review_email.contains("[快递公司]")){
 	 						review_email = review_email.replace("[快递公司]", express_cpn);
 	 					}
 	 					if(review_email.contains("[快递单号]")){
 	 						review_email = review_email.replace("[快递单号]", express_no);
 	 					}
 	 					if(review_email.contains("[日期]")){
 	 						review_email = review_email.replace("[日期]", express_data);
 	 					}
 	 					if(review_email.contains("[单据号]")){
 	 						review_email = review_email.replace("[单据号]", doc_no);
 	 					}
 	 					// msg
 	 					if(review_msg.contains("[收件人名称]")){
 	 						review_msg = review_msg.replace("[收件人名称]", recipient_name);
 	 					}
 	 					if(review_msg.contains("[公司名称]")){
 	 						review_msg = review_msg.replace("[公司名称]", cpn_name);
 	 					}
 	 					if(review_msg.contains("[快递公司]")){
 	 						review_msg = review_msg.replace("[快递公司]", express_cpn);
 	 					}
 	 					if(review_msg.contains("[快递单号]")){
 	 						review_msg = review_msg.replace("[快递单号]", express_no);
 	 					}
 	 					if(review_msg.contains("[日期]")){
 	 						review_msg = review_msg.replace("[日期]", express_data);
 	 					}
 	 					if(review_msg.contains("[单据号]")){
 	 						review_msg = review_msg.replace("[单据号]", doc_no);
 	 					}
 	 					flag = true;
 	 				} catch (Exception e) {
 	 					logger.debug("Exception:", e);
 	 					writer.print("");
 	 				}
 	 				
 					if (flag) {
 						result.put("review_to", review_to);
 		 				result.put("review_cc", review_cc);
 		 				result.put("review_bcc", review_bcc);
 		 				result.put("review_subject", review_subject);
 		 				result.put("review_email", review_email);
 		 				result.put("review_msg", review_msg);
 		 				
 						result.put("resultcode", 0);
 						String returnMsg = JackJson.fromObjectToJson(result);
 						logger.debug("{}", returnMsg);
 						writer.print(returnMsg);
 					}
 				} else {
 					result.put("resultcode", 1);
					String returnMsg = JackJson.fromObjectToJson(result);
					logger.debug("{}", returnMsg);
					writer.print(returnMsg);
 				}
			} else {
				logger.debug("{}", false);
				writer.print("");
			}
		} catch (Exception e) {
			logger.error("Exception: ", e);
		} finally {
			writer.flush();
			writer.close();
		}
	}
	
	/**
	 * 获取单据状态为已寄出的客户名称
	 */
	@RequestMapping(value = "/getCusName")
	public void getCusName(ExtPager page, HttpSession session,
			HttpServletRequest request, HttpServletResponse response,
			PrintWriter writer) {
		response.setContentType("text/plain;charset=UTF-8");
		ArrayList<HashMap<String, Object>> result = null;
		try {
			String companyId=session.getAttribute(WebConstants.CURRENT_COMPANY)
					.toString();
			HashMap<String, Object> param = new HashMap<String, Object>();
			param.put("companyId", companyId);
			result = dealsendmsgservice.getCusName(param);
			String returnMsg = JackJson.fromObjectToJson(result);
			logger.debug("{}", returnMsg);
			writer.print(returnMsg);
		} catch (Exception e) {
			logger.error("Exception: ", e);
		} finally {
			writer.flush();
			writer.close();
		}
	}

	/**
	 * 获取单据状态为已寄出和已开票的单据号
	 */
	@RequestMapping(value = "/getDocNo")
	public void getDocNo(ExtPager page, HttpSession session,
			HttpServletRequest request, HttpServletResponse response,
			PrintWriter writer) {
		response.setContentType("text/plain;charset=UTF-8");
		ArrayList<HashMap<String, Object>> result = null;
		try {
			String companyId=session.getAttribute(WebConstants.CURRENT_COMPANY)
					.toString();
			HashMap<String, Object> param = new HashMap<String, Object>();
			param.put("companyId", companyId);
			result = dealsendmsgservice.getDocNo(param);
			String returnMsg = JackJson.fromObjectToJson(result);
			logger.debug("{}", returnMsg);
			writer.print(returnMsg);
		} catch (Exception e) {
			logger.error("Exception: ", e);
		} finally {
			writer.flush();
			writer.close();
		}
	}

	/**
	 * 发送邮件，短信
	 */
	@RequestMapping(value = "/SendMessage")
	public void SendMessage(ExtPager page, HttpSession session,
			HttpServletRequest request, HttpServletResponse response,
			PrintWriter writer) {

		HashMap<String, Object> param = new HashMap<String, Object>();
		HashMap<String, Object> result = new HashMap<String, Object>();
		response.setContentType("text/plain;charset=UTF-8");
		// 单据号码
		String doc_no = request.getParameter("doc_no");
		String cpnId = session.getAttribute(WebConstants.CURRENT_COMPANY).toString();
		try {
			User user = (User) session.getAttribute(WebConstants.CURRENT_USER);
			if (user != null) {
				String[] doc_no_list = doc_no.split(",");
				List<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
				for(int i = 0; i < doc_no_list.length; i++){
					HashMap<String, String> map = new HashMap<String, String>();
					map.put("doc_no", doc_no_list[i]);
					list.add(map);
				}
				param.put("doc_no", list);
				param.put("cpnId", cpnId);
				param.put("type", 1);
				// 获得邮件短信设置信息
 				ArrayList<HashMap<String, Object>> logsformodel = dealsendmsgservice.getMsgForPreview(param);
 				int useFlag = Integer.parseInt(logsformodel.get(0).get("useFlag").toString());
 				if (useFlag == 2 || useFlag == 3) {
 	 				// 获得邮件信息
 	 				ArrayList<HashMap<String, Object>> logs = dealsendmsgservice.getMsgForMail(param);
 	 				
 	 				String review_to = null;
 	 				String review_cc = null;
 	 				String review_bcc = null;
 	 				String review_subject = null;
 	 				String review_email = null;
 	 				String host = null;
 	 				String port = null;
 	 				String username = null;
 	 				String password = null;
 	 				boolean flag = false;
 	 				try {
 	 					// 收件人
 	 	 				review_to = logsformodel.get(0).get("review_to").toString();
 	 	 				review_cc = logsformodel.get(0).get("review_cc").toString();
 	 	 				review_bcc = logsformodel.get(0).get("review_bcc").toString();
 	 	 				// 邮件主题
 	 	 				review_subject = logsformodel.get(0).get("review_subject").toString();
 	 	 				// 邮件内容
 	 	 				review_email = logsformodel.get(0).get("review_email").toString();
 	 	 				
 	 					// 邮件服务器地址
 	 					host = Const.PROPERTIES.getProperty("mailserverhost");
 	 					// 邮件服务器端口
 	 					port = Const.PROPERTIES.getProperty("mailserverport");
 	 					// 邮箱用户名
 	 					username = Const.PROPERTIES.getProperty("mailusername");
 	 					// 邮箱密码
 	 					password = Const.PROPERTIES.getProperty("mailpassword");
 	 					flag = true;
 	 				} catch (Exception e){
 						System.out.println(e);
 					}
 					/************ 发送邮件 */
 	 				if (flag) {
 	 				// 循环发送邮件
 	 					for(int j = 0; j < logs.size(); j++) {
 	 						try {
 	 							// 收件人名称
 	 			 				String recipient_name = logs.get(j).get("recipient_name").toString();
 	 			 				// 收件人邮箱
 	 			 				String recipient_email = logs.get(j).get("recipient_email").toString();
 	 			 				// 公司名称
 	 			 				String cpn_name = logs.get(j).get("cpn_name").toString();
 	 			 				// 快递公司
 	 			 				String express_cpn = logs.get(j).get("express_cpn").toString();
 	 			 				// 快递单号
 	 			 				String express_no = logs.get(j).get("express_no").toString();
 	 			 				// 日期
 	 			 				String express_data = logs.get(j).get("express_data").toString();
 	 			 				
 	 			 				// to
 	 							if(review_to.contains("[收件人邮箱]")){
 	 								review_to = review_to.replace("[收件人邮箱]", recipient_email);
 	 							}
 	 							// cc
 	 							if(review_cc.contains("[收件人邮箱]")){
 	 								review_cc = review_cc.replace("[收件人邮箱]", recipient_email);
 	 							}
 	 							// bcc
 	 							if(review_bcc.contains("[收件人邮箱]")){
 	 								review_bcc = review_bcc.replace("[收件人邮箱]", recipient_email);
 	 							}
 	 							// subject
 	 							if(review_subject.contains("[公司名称]")){
 	 								review_subject = review_subject.replace("[公司名称]", cpn_name);
 	 							}
 	 							if(review_subject.contains("[快递单号]")){
 	 								review_subject = review_subject.replace("[快递单号]", express_no);
 	 							}
 	 							if(review_subject.contains("[日期]")){
 	 								review_subject = review_subject.replace("[日期]", express_data);
 	 							}
 	 							// mail
 	 							if(review_email.contains("[收件人名称]")){
 	 								review_email = review_email.replace("[收件人名称]", recipient_name);
 	 							}
 	 							if(review_email.contains("[公司名称]")){
 	 								review_email = review_email.replace("[公司名称]", cpn_name);
 	 							}
 	 							if(review_email.contains("[快递公司]")){
 	 								review_email = review_email.replace("[快递公司]", express_cpn);
 	 							}
 	 							if(review_email.contains("[快递单号]")){
 	 								review_email = review_email.replace("[快递单号]", express_no);
 	 							}
 	 							if(review_email.contains("[日期]")){
 	 								review_email = review_email.replace("[日期]", express_data);
 	 							}
 	 							if(review_email.contains("[单据号]")){
 	 								review_email = review_email.replace("[单据号]", doc_no);
 	 							}
 	 						} catch (Exception e){
 	 							System.out.println(e);
 	 						}
 	 						
 	 						MailSenderInfo mailInfo = new MailSenderInfo();
 	 						GmailSenderInfo gmail = new GmailSenderInfo();
 	 						SimpleMailSender sms = new SimpleMailSender();;
 	 						GmailSender gmailsender = new GmailSender();
 	 						if (port.equals("465")) {
 	 							gmail.setContent(review_email);
 	 	 						gmail.setHost(host);
 	 	 						gmail.setPassword(password);
 	 	 						gmail.setPort(port);
 	 	 						gmail.setSubject(review_subject);
 	 	 						gmail.setUsername(username);
 	 						} else {
 	 						// 邮件设置
 	 	 						mailInfo.setMailServerHost(host);
 	 	 						mailInfo.setMailServerPort(port);
 	 	 						mailInfo.setValidate(true);
 	 	 						mailInfo.setUserName(username);
 	 	 						mailInfo.setPassword(password);
 	 	 						mailInfo.setFromAddress(username);
 	 	 						mailInfo.setSubject(review_subject);
 	 	 						mailInfo.setContent(review_email);
 	 						}
 	 						
 	 						if (!Tools.isEmpty(review_to)) {
 	 							String[] reviewToList = review_to.split(";");
 	 							for (int i = 0; i < reviewToList.length; i++) {
 	 								if (port.equals("465")) {
 	 									gmail.setMailTo(reviewToList[i]);
 	 									gmailsender.mailsend(gmail);
 	 								} else {
 	 									mailInfo.setToAddress(reviewToList[i]);
 	 	 								sms.sendTextMail(mailInfo);
 	 								}
 	 							}
 	 						}
 	 						if (!Tools.isEmpty(review_cc)) {
 	 							String[] reviewCcList = review_cc.split(";");
 	 							for (int i = 0; i < reviewCcList.length; i++) {
 	 								if (port.equals("465")) {
 	 									gmail.setMailTo(reviewCcList[i]);
 	 									gmailsender.mailsend(gmail);
 	 								} else {
 	 									mailInfo.setToAddress(reviewCcList[i]);
 	 	 								sms.sendTextMail(mailInfo);
 	 								}
 	 							}
 	 						}
 	 						
 	 						if (!Tools.isEmpty(review_bcc)) {
 	 							String[] reviewBccList = review_bcc.split(";");
 	 							for (int i = 0; i < reviewBccList.length; i++) {
 	 								if (port.equals("465")) {
 	 									gmail.setMailTo(reviewBccList[i]);
 	 									gmailsender.mailsend(gmail);
 	 								} else {
 	 									mailInfo.setToAddress(reviewBccList[i]);
 	 	 								sms.sendTextMail(mailInfo);
 	 								}
 	 							}
 	 						}
 	 						
 	 						String doc_no_sent = logs.get(j).get("doc_no").toString();
 	 						String companyId=session.getAttribute(WebConstants.CURRENT_COMPANY)
 	 								.toString();
 	 						HashMap<String, Object> param2 = new HashMap<String, Object>();
 	 						param2.put("companyId", companyId);
 	 						param2.put("doc_no", doc_no_sent);
 	 						int edit = dealsendmsgservice.updateSentDoc(param2);
 	 						if (edit == 0) {
 	 							// 如果发送邮件没有出错，循环到最后一次给返回值0
 	 							if (j == logs.size()-1) {
 	 								result.put("docStatus", 0);
 	 							}
 	 						} else {
 	 							result.put("docStatus", 1);
 	 							result.put("docNo", doc_no_sent);
 	 							return;
 	 						}
 	 					}
 	 					result.put("resultcode", 0);
 	 					String returnMsg = JackJson.fromObjectToJson(result);
 	 					logger.debug("{}", returnMsg);
 	 					writer.print(returnMsg);
 	 				}
 				} else {
 					result.put("resultcode", 1);
 					String returnMsg = JackJson.fromObjectToJson(result);
 					logger.debug("{}", returnMsg);
 					writer.print(returnMsg);
 				}
			} else {
				logger.debug("{}", false);
				writer.print("");
			}
		} catch (Exception e) {
			logger.error("Exception: ", e);
		} finally {
			writer.flush();
			writer.close();
		}
	}
	
	/**
	 * 获取单据状态为已寄出和已开票的发票号码
	 */
	@RequestMapping(value = "/getDealSendExpressNo")
	public void getDealSendExpressNo(ExtPager page, HttpSession session,
			HttpServletRequest request, HttpServletResponse response,
			PrintWriter writer) {
		response.setContentType("text/plain;charset=UTF-8");
		ArrayList<HashMap<String, Object>> result = null;
		try {
			String companyId=session.getAttribute(WebConstants.CURRENT_COMPANY)
					.toString();
			HashMap<String, Object> param = new HashMap<String, Object>();
			param.put("companyId", companyId);
			
			result = dealsendmsgservice.getDealSendExpressNo(param);
			String returnMsg = JackJson.fromObjectToJson(result);
			logger.debug("{}", returnMsg);
			writer.print(returnMsg);
		} catch (Exception e) {
			logger.error("Exception: ", e);
		} finally {
			writer.flush();
			writer.close();
		}
	}
	
	/**
	 * 获取单据状态为已寄出和已开票的单据号
	 */
	@RequestMapping(value = "/getDealSendCust")
	public void getDealSendCust(ExtPager page, HttpSession session,
			HttpServletRequest request, HttpServletResponse response,
			PrintWriter writer) {
		response.setContentType("text/plain;charset=UTF-8");
		ArrayList<HashMap<String, Object>> result = null;
		try {
			String companyId=session.getAttribute(WebConstants.CURRENT_COMPANY)
					.toString();
			HashMap<String, Object> param = new HashMap<String, Object>();
			param.put("companyId", companyId);
			
			result = dealsendmsgservice.getDealSendCust(param);
			String returnMsg = JackJson.fromObjectToJson(result);
			logger.debug("{}", returnMsg);
			writer.print(returnMsg);
		} catch (Exception e) {
			logger.error("Exception: ", e);
		} finally {
			writer.flush();
			writer.close();
		}
	}
}